package com.example.certificate.controller;

import com.example.certificate.annoatiton.LoginToken;
import com.example.certificate.entity.OrgUser;
import com.example.certificate.entity.User;
import com.example.certificate.mapper.OrgUserMapper;
import com.example.certificate.mapper.UserMapper;
import com.example.certificate.utils.ResultEntity;
import com.example.certificate.vo.UserInfoVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 系统用户 前端控制器
 * </p>
 *
 * @author hao
 * @since 2022-02-16 11:29:59
 */
@RestController
@RequestMapping("/certificate/orgUser")
public class OrgUserController {

    @Resource
    private OrgUserMapper orgUserMapper;

    @Resource
    private UserMapper userMapper;

    @LoginToken
    @ApiOperation(value = "修改用户信息")
    @PostMapping(value = "/updateLoader")
    public ResultEntity updateLoader(@RequestBody UserInfoVo userInfoVo){
       OrgUser orgUser = orgUserMapper.selectById(userInfoVo.getId());
       orgUser.setIdentityCard(userInfoVo.getIdentityCard());
       orgUser.setNickname(userInfoVo.getNickname());
       orgUser.setName(userInfoVo.getName());
       orgUser.setGender(userInfoVo.getGender());
       orgUser.setEmail(userInfoVo.getEmail());
       orgUserMapper.updateById(orgUser);

        User user = userMapper.selectById(userInfoVo.getId());
        user.setPwd(userInfoVo.getPassword());
        userMapper.updateById(user);

        return new ResultEntity();

    }
}

